HTMLCollection.prototype.forEach=Array.prototype.forEach;

String.prototype.format=function (obj,flag){
	flag=flag||false;
	return this.replace(/\{#.+?\}/g,function(w){ 
				var temp=w.replace(/[\{#\}]/g,'');
				if(temp in obj) return obj[temp];
				if(flag){
					return '';
				}
				return w; 
			});
};

(function (jQuery,$){
	
	if(!$.net){
		$.net={'config':{}};
	}
	
	$.getDate=function (f,obj){
		if(typeof f=="undefined"){
			return "";
		}
		if($.isFunction(f)){
			if(!!obj){
				return f.call(obj);
			}else{
				return f();
			}
		}else{
			return f;
		}
	}
	
	$._toSExpand=function(obj){
		var html="";
		for(var i in obj){
			html+="&"+i+"="+obj[i];
		}
		return html.substr(1);
	}
	
	$._ckString=function(obj,href){
		var str='';
		if(!!href){
			for(var c in obj){
				if(href.indexOf(c)!=-1){
					str+=obj[c];
				}
			}
		}else{
			for(var c in obj){
				str+=obj[c];
			}
		}
		return str;
	}
	
	$.net.ajax=function(opt){
		var _config={
			'method':'GET',
			'headers':{},
			'body':'',
			'_reloadT':1000,
			'state':'init',
			'listener':{},
			'_getParam':function(){
				return;
			},
			'timeID':0
		}
		$.extend(this,_config,opt);
		this.req=gw.req();
		var obj=this;
		["load","error","progress"].forEach(function(v){
			obj.req.addEventListener(v, function (){
				obj.state=v;
				if(v=="load"||v=="error"){
					clearTimeout(obj.timeID);
				}
				if(!!obj.listener[v]){
					if(obj.listener[v].call(obj)==true){
						obj.req.removeEventListener(v,arguments.callee,true);
					}	
				}					
			}, true);
		})
	}
	$.net.ajax.prototype={
		'post':function (obj){
			obj=obj||this;
			var req=obj.req;
			obj._getParam();
			req.open(obj.method,obj.url,true);
			if(obj.method=="POST"){
				req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			}
			for(var i in obj.headers){
				if(obj.headers.hasOwnProperty(i)){
					req.setRequestHeader(i,obj.headers[i]);
				}
			}
			obj.state='post';
			req.send(obj.body);
			if(!!obj._reloadT){
				obj.timeID=setTimeout(obj.reload,obj._reloadT,obj);		
			}
			return this;
		},
		'reload':function(obj){
			obj=obj||this;
			if(!!obj.listener.reload){
				obj.listener.reload.call(obj);
			}
			obj.state='reload';
			clearTimeout(obj.timeID);
			obj.timeID=0;
			if(obj.req.readyState<3){
				obj.req.abort();
				obj.post();
			}
			
		},
		'_reConfig':function(opt){
			$.extend(this,opt);
			return this;
		}
	}
	
})(___jQuery,___jQuery);